#include<iostream>
#include<stdio.h>
#include<string.h>
#define max 100
using namespace std;
typedef enum { hc, la, lb, lc, ld, ra, rb, rc, rd, other }symbol;
typedef symbol ElementType;
typedef int Position;
typedef struct SNode* PtrToSNode;
struct SNode {
	ElementType* Date;
	Position Top;
	int MaxSize;
};
typedef PtrToSNode Stack;

Stack CreateStack(int MaxSize)
{
	Stack S = (Stack)malloc(sizeof(struct SNode));
	S->Date = (ElementType*)malloc(MaxSize * sizeof(ElementType));
	S->Top = -1;
	S->MaxSize = MaxSize;
	return S;
}

void push(Stack S, ElementType X)
{
	S->Date[++(S->Top)] = X;
}
bool isempty(Stack S)
{
	return(S->Top == -1);
}
ElementType popvalue(Stack S)
{
	return (S->Date[S->Top]);
}
void pop(Stack S)
{
	(S->Top)--;
}

bool isend(int newline, char* c)
{
	if (newline && (*c) == '.')
	{
		scanf("%c", c);
		if ((*c) == '\n')
			return true;
		else
			return false;
	}
	else
		return false;
}

symbol getsymbol(char c)
{
	switch (c) {
	case '\n':
		return hc;
	case '/':
		scanf("%c", &c);
		if (c == '*')
			return la;
		else
			return getsymbol(c);
	case '{':
		return lb;
	case '[':
		return lc;
	case '(':
		return ld;
	case '*':
		scanf("%c", &c);
		if (c == '/')
			return ra;
		else
			return getsymbol(c);
	case '}':
		return rb;
	case ']':
		return rc;
	case ')':
		return rd;
	default:
		return other;
	}
}
bool match(symbol t1, symbol t2)
{
	return (t1 - t2) == 4;
}
void Print(symbol t)
{
	switch (t) {
	case la:
		printf("/*");
		break;
	case lb:
		printf("{");
		break;
	case lc:
		printf("[");
		break;
	case ld:
		printf("(");
		break;
	case ra:
		printf("*/");
		break;
	case rb:
		printf("}");
		break;
	case rc:
		printf("]");
		break;
	case rd:
		printf(")");
		break;
	default:
		break;
	}
}

int check(symbol* t1, symbol* t2)
{
	Stack S;
	char c;
	symbol t;
	int newline, error;
	S = CreateStack(max);
	newline = 1;
	error = 0;
	while (1)
	{
		scanf("%c", &c);
		if (isend(newline, &c))
			break;
		else
		{
			switch (t = getsymbol(c))
			{
			case la:
			case lb:
			case lc:
			case ld:
				push(S, t);
				newline = 0;
				break;
			case ra:
			case rb:
			case rc:
			case rd:
				if (isempty(S))
					error = 1;
				else if (!match(t, popvalue(S)))
					error = 2;
				else
					pop(S);
				newline = 0;
				break;
			case hc:
				newline = 1;
				break;
			default:
				newline = 0;
				break;
			}
			if (error)
				break;
		}
	}
	if (!error && !isempty(S))
		error = 2;
	(*t1) = t;
	(*t2) = popvalue(S);
	return error;
}
int main()
{
	symbol t1, t2;
	int error = check(&t1, &t2);

	if (!error)
		printf("YES\n");
	else
	{
		printf("NO\n");
		switch (error)
		{
		case 1:
			printf("?-");
			Print(t1);
			break;
		case 2:
			Print(t2);
			printf("-?");
			break;
		default:
			break;
		}
		printf("\n");
	}
	system("pause");
	return 0;
}
